home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
-
- OpenWindow by Cameron
-
- *******************************************************************************/
-
- #include <String.h>
-
- /* Type 1 includes */
- #include <Types.h>
- #include <QuickDraw.h>
-
- /* Type 2 includes */
- #include <Controls.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <OSUtils.h>
- #include <Resources.h>
- #include <SegLoad.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Traps.h>
- #include <Script.h>
-
- /* Type 3 includes */
- #include <Desk.h>
- #include <Files.h>
- #include <OSEvents.h>
- #include <Windows.h>
-
- /* Type 4 includes */
- #include <Dialogs.h>
-
- /* Global Variables */
-
- Str255 WindTitle;
- WindowPtr MyWindow,aWindPtr;
- short err,keycode,StartV,StartH;
- EventRecord MyEvent;
- Boolean quit,DrawOn;
- Rect WindRect,Rect1,Rect2;
- Point aPoint,lastPoint;
- long KCHRID,newKey,state;
- Handle KCHRHdl;
-
- extern void PATCHKEYTRANS();
- extern void UNPATCH();
-
- /*************************************************************************************/
- void InitMac()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
- InitCursor();
- quit = false;
- DrawOn = false;
- StartV = 25;
- StartH = 5;
- }
- /*************************************************************************************/
- void DoCR()
- {
- if (lastPoint.v > (*MyWindow).portRect.bottom-15)
- {
- EraseRect(&(*MyWindow).portRect);
- lastPoint.v = StartV;
- lastPoint.h = StartH;
- }
- else
- {
- lastPoint.v = lastPoint.v+14;
- lastPoint.h = StartH;
- }
- }
- /*************************************************************************************/
- void DoDraw()
- {
- DrawOn = true;
- GlobalToLocal(&MyEvent.where);
- MoveTo(MyEvent.where.h,MyEvent.where.v);
- EraseRect(&WindRect);
- }
- /*************************************************************************************/
- void DoKeyDown()
- {
- if (BitAnd(MyEvent.message,charCodeMask) == 'q' // if the user typed the magic "cmd-q" sequence,
- && BitAnd(MyEvent.modifiers,0x0100))
- { quit = true; } // it's Miller time!
- else {
- MoveTo(lastPoint.h,lastPoint.v);
- newKey = BitAnd(MyEvent.message,keyCodeMask); // Strip out all but the keycode
- newKey = BitShift(newKey,-8); // move the keycode down to the low byte
- keycode = LoWord(newKey); // extract the low word of the event message (ignore modifier bits)
- keycode = keycode & 0xFF7F; // make sure it looks like a key down stroke
- newKey = KeyTrans(*KCHRHdl, keycode, &state); // have KeyTrans translate the key code to ASCII
- keycode = LoWord(newKey); // now get the ASCII 2 value (IM5, p195 has it backward!)
- DrawChar(keycode); // just to make sure, let's have a look
- GetPen(&lastPoint); // now make sure we stay inside the content region
- if (lastPoint.h > ((*MyWindow).portRect.right-10)) // if we're getting to close to the edge,
- { DoCR(); } // go fix it up
- }
- }
- /*************************************************************************************/
- main()
- {
- InitMac();
-
- MyWindow = GetNewWindow(2009,nil,(WindowPtr)-1);
-
- if (MyWindow)
- {
- SetPort(MyWindow);
- MoveTo(StartH,StartV);
- lastPoint.h = StartH;
- lastPoint.v = StartV;
- KCHRID = GetScript(smRoman, smScriptKeys); /* returns resource ID of KCHR being used by system */
- KCHRHdl = GetResource('KCHR',KCHRID);
- if (KCHRHdl)
- {
- MoveHHi(KCHRHdl);
- HLock(KCHRHdl);
- PATCHKEYTRANS();
- while (quit != true)
- {
- if (DrawOn)
- {
- if (StillDown())
- {
- GetMouse(&aPoint);
- StdLine(aPoint);
- }
- else { DrawOn = false; }
- }
- else
- {
- if (WaitNextEvent(everyEvent,&MyEvent,0,nil))
- {
- switch (MyEvent.what)
- {
- case mouseDown:
- {
- if ((FindWindow(MyEvent.where,&aWindPtr) == inContent) // make sure the mouseDown is
- && (aWindPtr == MyWindow)) // where we want it
- { DoDraw(); } // set up for drawing a line
- else if (FindWindow(MyEvent.where,&aWindPtr) == inGoAway) // on the other hand, if it's in the goAway box,
- { quit = true; } // we can take a hint!
- break;
- }
- case keyDown:
- {
- DoKeyDown();
- break;
- }
- case autoKey:
- {
- DoKeyDown();
- break;
- }
- }
- }
- }
- }
- UNPATCH();
- }
- }
- }